package com.crb.crm.manage.message;


import com.crb.crm.manage.message.alarm.Alarm;
import com.crb.crm.manage.message.common.MessagSenderContext;
import com.crb.crm.manage.message.common.SAGTemplate;
import com.crb.crm.manage.message.common.SMGChannel;
import com.google.common.collect.Maps;
import lombok.Data;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Package: com.crb.ecsb.message
 * Author: huangjian
 * Date:  2020/8/28 14:42
 * Modified By:
 * @author huangjian
 */
@Component
public class SystemAlarm {

    @Autowired
    private MessagSenderContext messagSenderContext;

    public void sendAlarm(Alarm alarm)  {
        Map<String, String> param = Maps.newHashMap();
        try {
            param = BeanUtils.describe(alarm);
        } catch (Exception e) {
            e.printStackTrace();
        }
        messagSenderContext.channel(SMGChannel.DING_DING).template(alarm.support()).sendMessage(param, alarm.getReceiver());
    }


    @Data
    public static class AlarmLogin extends Alarm{
        private String code;
        private String mobile;
        @Override
        public  SAGTemplate support(){
            return SAGTemplate.USER_LOGIN;
        }
    }

    @Data
    public static class AlarmUserModifyPwd extends Alarm{
        private String code;
        @Override
        public  SAGTemplate support(){
            return SAGTemplate.USER_MODIFY_PWD;
        }
    }
}
